import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { AdminService } from './admin.service';
// import { AuthGuard } from '../auth/auth.guard';
import { AuthGuard } from '@nestjs/passport';

@Controller('admin')
@UseGuards(AuthGuard('jwt'))
export class AdminController {
  constructor(private readonly adminSevice: AdminService) {}

  @Get()
  async getUsers() {
    const user = await this.adminSevice.findAll();

    // console.log('user', user);
    return '123';
  }

  @Get('/add')
  async addUser(
    @Query('u') u: string,
    @Query('p') p: string,
  ) {
    return await this.adminSevice.create({
      username: u,
      password: p,
    });
  }

  @Get('/sea')
  async getUser(
    @Query('u') u: string,
  ) {
    return await this.adminSevice.findOne({ username: u });
  }

  @Get('/login')
  async login(
    @Query('u') u: string,
    @Query('p') p: string
  ) {
    return await this.adminSevice.login({ username: u, password: p});
  }

  @Get('/edit')
  async edit(
    @Query('u') u: string,
    @Query('p') p: string
  ) {
    return this.adminSevice.edit({ username: u, password: p });
  }
}
